﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Microsoft.ReportingServices;
using Microsoft.Reporting;
using Microsoft.Reporting.WinForms;

using System.Collections.ObjectModel;

using P2.Cuberry.Modules.Framework.LocalCuberryReport;

using P2.Cuberry.Framework.BOLBase;
using P2.Cuberry.Framework.Helper;
using P2.Cuberry.Framework.Helper.Configuration;
using P2.Cuberry.Modules.Framework.LocalCuberryReport.DAL;


namespace P2.Cuberry.Modules.Framework.LocalCuberryReport.Controls
{
    class FiscalYearComboBox : System.Windows.Controls.ComboBox
    {
        //private System.Windows.Controls.ComboBox fyCBox = new System.Windows.Controls.ComboBox(); 

        public FiscalYearComboBox(Thickness cbMargins, int cbWidth, int cbHight)
        {          
            this.Name = "FiscalYear";
            this.Width = cbWidth;
            this.Height = cbHight;
            this.Margin = cbMargins;
            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.SelectedValuePath = "FiscalYearID";
            this.DisplayMemberPath = "FiscalYearName";

            this.GetFiscalYears();
            this.ItemsSource = _fiFiscalYearDictionary;
        }

        
        private Dictionary<int, string> _fiFiscalYearDictionary = new Dictionary<int, string>();

        private void GetFiscalYears()
        {
            try
            {               
                    _fiFiscalYearDictionary.Clear();

                    string connectionString = ConfigurationSetUp.GetEntConnectionString("Business", Properties.Settings.Default.EntityResources);
                    using (LocalCuberryReportDataModel db = new LocalCuberryReportDataModel(connectionString))
                    {
                        var fiscalYears = from fy in db.FiFiscalYear
                                          orderby fy.FiscalYearName descending
                                          select fy;
                        foreach (var fiscalYear in fiscalYears)
                        {                            
                            _fiFiscalYearDictionary.Add(fiscalYear.FiscalYearID, fiscalYear.FiscalYearName);
                        }                     
                    }                
            }
            catch (Exception ex) //AM:TC
            {
                P2ExceptionHandler.LogException(ex, string.Format("{0}.{1}", "FiFiscalYear", System.Reflection.MethodInfo.GetCurrentMethod().Name));
            }
        }



    }
}
